package com.chenglai.goods.dao;

import com.chenglai.goods.pojo.Goods;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author yawang
 * @create 2023/11/14 17:27:41
 **/
@Repository
public interface GoodsMapper extends Mapper<Goods> {
    @Select("<script>" +
            "select a.*,b.classify_name from t_cl_goods a " +
            "left join t_cl_goodsClassify b on a.goods_classify = b.classify_id " +
            "where a.shop_id = #{shopId} " +
            "<if test='categoryId!=0'> and a.goods_classify = #{classifyId} </if>" +
            "<if test='startTime!=\" \"'> and a.create_time &gt;#{startTime} and a.create_time &lt;#{endTime} </if> " +
            "<if test='search!=\" \"'> and (a.goods_name like ${search} or a.goods_id = ${search})</if>" +
            "order by a.goods_id desc" +
            "</script>")
    List<Goods> listGoods(Integer categoryId,String startTime,String endTime,Integer shopId,String search);

    @Insert("insert into t_cl_goods values (#{goodsName},#{goodsTitle},#{goodsKey},#{goodsSort},#{goodsClassify}," +
            "#{goodsStatus},#{goodsDetail},#{createTime}," +
            "#{goodsInventory},#{goodsOriginalPrice},#{goodsSalePrice})")
    @Options(useGeneratedKeys = true, keyProperty = "attrGroupId")
    void insertGoods(Goods goods);


    @Select("select a.group_id,a.goods_group_price,a.goods_group_number,b.* from t_cl_goods_group_on a left join t_cl_goods b on a.goods_id =b.goods_id where b.shop_id = #{shopId}")
    List<Goods> listGroupGoods(@Param("shopId")Integer shopId);

}
